#include "stdafx.h"
#include "GameObject.h"
#include "..\World\ChunkManager.h"
#include "..\..\EdgeGraphics\GraphicsManager.h"
#include "..\..\EdgeGraphics\Model.h"
#include "..\..\EdgeGraphics\Lighting\LightingEngine.h"
#include "..\..\EdgeMath\Vectors.h"
#include "..\..\EdgeMath\IBoundingShape.h"
#include "..\..\EdgeGraphics\Camera.h"

GameObject::GameObject(void)
{

}
/*virtual*/GameObject::~GameObject(void)
{
	if (model)
		delete model;
	if (collider)
		delete collider;
}

/////////////////////<Abstract functions>//////////////////////////////////////////
/*virtual*/ void GameObject::Update(float dt) /*override*/
{
	// compute acceleration from the total number of forces applied
	for (unsigned int i = 0; i < total_forces.size(); i++)
		acceleration += total_forces[i] * (1.f / mass);

	total_forces.clear();

	// update position and velocity
	velocity += acceleration * dt;
	position += velocity * dt;
}

/*virtual*/ void GameObject::Draw(void) /*override*/
{
	LightingEngine::GetInstance()->world.world = getWorldTransform();
	LightingEngine::GetInstance()->world.gMVP = getWorldTransform() * Camera::GetInstance()->getView() * Camera::GetInstance()->getProj();
	LightingEngine::GetInstance()->world_buffer->Bind();
	
	// draw the model if it's not null
	if (model)
		GraphicsManager::GetInstance()->Draw(model);
}